package com.infocollect.project.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.infocollect.project.api.entity.TappPowerRoleEntity;
import com.infocollect.project.api.mapper.TappPowerRoleMapper;
import com.infocollect.project.api.service.ITappPowerRoleService;
import org.springframework.stereotype.Service;

/**
 * (TappPowerrole)表服务实现类
 *
 * @author makejava
 * @since 2019-12-25 10:32:29
 */
@Service("tappPowerroleService")
public class TappPowerRoleServiceImpl extends ServiceImpl<TappPowerRoleMapper, TappPowerRoleEntity> implements ITappPowerRoleService {

    /**
     * 通过ID查询单条数据
     *
     * @param fid 主键
     * @return 实例对象
     */
    @Override
    public TappPowerRoleEntity queryById(Long fid) {
        return this.baseMapper.selectById(fid);
    }



    /**
     * 新增数据
     *
     * @param tappPowerrole 实例对象
     * @return 实例对象
     */
    @Override
    public TappPowerRoleEntity insert(TappPowerRoleEntity tappPowerrole) {
        this.baseMapper.insert(tappPowerrole);
        return tappPowerrole;
    }

    /**
     * 修改数据
     *
     * @param tappPowerrole 实例对象
     * @return 实例对象
     */
    @Override
    public TappPowerRoleEntity update(TappPowerRoleEntity tappPowerrole) {
        this.baseMapper.updateById(tappPowerrole);
        return this.queryById(tappPowerrole.getFid());
    }

    /**
     * 通过主键删除数据
     *
     * @param fid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long fid) {
        return this.baseMapper.deleteById(fid) > 0;
    }




    /**
     * 通过角色id删除
     *
     * @param roleid 角色id
     * @return 影响行数
     */
    @Override
    public Boolean deleteByRoleId(Long roleid){
        QueryWrapper<TappPowerRoleEntity> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("froleid",roleid);
        return this.baseMapper.delete(queryWrapper) > 0;

    }
}